package com.marst.first.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.marst.first.bean.Menu;
import com.marst.first.bean.VO.Result;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Random;

@Mapper
public interface MenuMapper extends BaseMapper<Menu> {

    @Select("select count(1) from menu where name = #{name}")
    int getMenuCountByName(String name);

    @Update("update menu set is_delete=1 where id = #{id}")
    void deleteMenuOnLogic(int id);

    @Select("<script>                                              "+
            "SELECT                                                "+
            "	*                                                  "+
            "FROM                                                  "+
            "	menu                                               "+
            "WHERE                                                 "+
            " 1=1                                                  "+
            "<if test=\" name != null and name != '' \">             "+
            "	AND `name` LIKE CONCAT('%','${name}','%' )         "+
            "</if>                                                 "+
            "<if test=\" url != null and url != '' \">               "+
            "	AND `url` LIKE CONCAT('%','${url}','%' )           "+
            "</if>                                                 "+
            "</script>                                             ")
    List<Menu> getMenuList(String name, String url);


    @Select("select id, name from menu ")
    List<Menu> getAllMenuList();
}
